home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 November / CHIP Kasım 1996.iso / ms / visualj / vjtrialb.exe / RCDATA / CABINET / MFCAPWZ.DLL / TEMPLATE / CNTRITEM.CPP < prev    next >
C/C++ Source or Header  |  1996-07-31  |  5KB  |  201 lines

  1. // $$cntritem_ifile$$.cpp : implementation of the $$CNTRITEM_CLASS$$ class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "$$root$$.h"
  6.  
  7. $$IF(CRecordView || CDaoRecordView)
  8. #include "$$recset_hfile$$.h"
  9. $$ENDIF
  10. #include "$$doc_hfile$$.h"
  11. #include "$$view_hfile$$.h"
  12. #include "$$cntritem_hfile$$.h"
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // $$CNTRITEM_CLASS$$ implementation
  22.  
  23. IMPLEMENT_SERIAL($$CNTRITEM_CLASS$$, $$CNTRITEM_BASE_CLASS$$, 0)
  24.  
  25. $$IF(CRichEditView)
  26. $$CNTRITEM_CLASS$$::$$CNTRITEM_CLASS$$(REOBJECT* preo, $$DOC_CLASS$$* pContainer)
  27.     : $$CNTRITEM_BASE_CLASS$$(preo, pContainer)
  28. $$ELSE //!CRichEditView
  29. $$CNTRITEM_CLASS$$::$$CNTRITEM_CLASS$$($$DOC_CLASS$$* pContainer)
  30.     : $$CNTRITEM_BASE_CLASS$$(pContainer)
  31. $$ENDIF //CRichEditView
  32. {
  33. $$IF(VERBOSE)
  34.     // TODO: add one-time construction code here
  35.     
  36. $$ENDIF
  37. }
  38.  
  39. $$CNTRITEM_CLASS$$::~$$CNTRITEM_CLASS$$()
  40. {
  41. $$IF(VERBOSE)
  42.     // TODO: add cleanup code here
  43.     
  44. $$ENDIF
  45. }
  46. $$IF(!CRichEditView)
  47.  
  48. void $$CNTRITEM_CLASS$$::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
  49. {
  50.     ASSERT_VALID(this);
  51.  
  52.     $$CNTRITEM_BASE_CLASS$$::OnChange(nCode, dwParam);
  53. $$IF(VERBOSE)
  54.  
  55.     // When an item is being edited (either in-place or fully open)
  56.     //  it sends OnChange notifications for changes in the state of the
  57.     //  item or visual appearance of its content.
  58.  
  59.     // TODO: invalidate the item by calling UpdateAllViews
  60.     //  (with hints appropriate to your application)
  61.  
  62.     GetDocument()->UpdateAllViews(NULL);
  63.         // for now just update ALL views/no hints
  64. $$ENDIF
  65. }
  66.  
  67. BOOL $$CNTRITEM_CLASS$$::OnChangeItemPosition(const CRect& rectPos)
  68. {
  69.     ASSERT_VALID(this);
  70. $$IF(VERBOSE)
  71.  
  72.     // During in-place activation $$CNTRITEM_CLASS$$::OnChangeItemPosition
  73.     //  is called by the server to change the position of the in-place
  74.     //  window.  Usually, this is a result of the data in the server
  75.     //  document changing such that the extent has changed or as a result
  76.     //  of in-place resizing.
  77.     //
  78.     // The default here is to call the base class, which will call
  79.     //  $$CNTRITEM_BASE_CLASS$$::SetItemRects to move the item
  80.     //  to the new position.
  81. $$ENDIF
  82.  
  83.     if (!$$CNTRITEM_BASE_CLASS$$::OnChangeItemPosition(rectPos))
  84.         return FALSE;
  85.  
  86. $$IF(VERBOSE)
  87.     // TODO: update any cache you may have of the item's rectangle/extent
  88.  
  89. $$ENDIF
  90.     return TRUE;
  91. }
  92.  
  93. void $$CNTRITEM_CLASS$$::OnGetItemPosition(CRect& rPosition)
  94. {
  95.     ASSERT_VALID(this);
  96. $$IF(VERBOSE)
  97.  
  98.     // During in-place activation, $$CNTRITEM_CLASS$$::OnGetItemPosition
  99.     //  will be called to determine the location of this item.  The default
  100.     //  implementation created from AppWizard simply returns a hard-coded
  101.     //  rectangle.  Usually, this rectangle would reflect the current
  102.     //  position of the item relative to the view used for activation.
  103.     //  You can obtain the view by calling $$CNTRITEM_CLASS$$::GetActiveView.
  104.  
  105.     // TODO: return correct rectangle (in pixels) in rPosition
  106. $$ENDIF
  107.  
  108.     rPosition.SetRect(10, 10, 210, 210);
  109. }
  110.  
  111. void $$CNTRITEM_CLASS$$::OnActivate()
  112. {
  113.     // Allow only one inplace activate item per frame
  114.     $$VIEW_CLASS$$* pView = GetActiveView();
  115.     ASSERT_VALID(pView);
  116.     COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView);
  117.     if (pItem != NULL && pItem != this)
  118.         pItem->Close();
  119.     
  120.     $$CNTRITEM_BASE_CLASS$$::OnActivate();
  121. }
  122.  
  123. void $$CNTRITEM_CLASS$$::OnDeactivateUI(BOOL bUndoable)
  124. {
  125.     $$CNTRITEM_BASE_CLASS$$::OnDeactivateUI(bUndoable);
  126.  
  127.     // Hide the object if it is not an outside-in object
  128.     DWORD dwMisc = 0;
  129.     m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc);
  130.     if (dwMisc & OLEMISC_INSIDEOUT)
  131.         DoVerb(OLEIVERB_HIDE, NULL);
  132. }
  133.  
  134. void $$CNTRITEM_CLASS$$::Serialize(CArchive& ar)
  135. {
  136.     ASSERT_VALID(this);
  137.  
  138. $$IF(VERBOSE)
  139.     // Call base class first to read in $$CNTRITEM_BASE_CLASS$$ data.
  140.     // Since this sets up the m_pDocument pointer returned from
  141.     //  $$CNTRITEM_CLASS$$::GetDocument, it is a good idea to call
  142.     //  the base class Serialize first.
  143. $$ENDIF
  144.     $$CNTRITEM_BASE_CLASS$$::Serialize(ar);
  145.  
  146. $$IF(VERBOSE)
  147.     // now store/retrieve data specific to $$CNTRITEM_CLASS$$
  148. $$ENDIF
  149.     if (ar.IsStoring())
  150.     {
  151. $$IF(VERBOSE)
  152.         // TODO: add storing code here
  153. $$ENDIF
  154.     }
  155.     else
  156.     {
  157. $$IF(VERBOSE)
  158.         // TODO: add loading code here
  159. $$ENDIF
  160.     }
  161. }
  162. $$IF(CONTAINER_SERVER)
  163.  
  164. BOOL $$CNTRITEM_CLASS$$::CanActivate()
  165. {
  166. $$IF(VERBOSE)
  167.     // Editing in-place while the server itself is being edited in-place
  168.     //  does not work and is not supported.  So, disable in-place
  169.     //  activation in this case.
  170. $$ENDIF
  171.     $$DOC_CLASS$$* pDoc = GetDocument();
  172.     ASSERT_VALID(pDoc);
  173.     ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(COleServerDoc)));
  174.     if (pDoc->IsInPlaceActive())
  175.         return FALSE;
  176.  
  177. $$IF(VERBOSE)
  178.     // otherwise, rely on default behavior
  179. $$ENDIF
  180.     return COleClientItem::CanActivate();
  181. }
  182. $$ENDIF
  183. $$ENDIF //!CRichEditView
  184.  
  185. /////////////////////////////////////////////////////////////////////////////
  186. // $$CNTRITEM_CLASS$$ diagnostics
  187.  
  188. #ifdef _DEBUG
  189. void $$CNTRITEM_CLASS$$::AssertValid() const
  190. {
  191.     $$CNTRITEM_BASE_CLASS$$::AssertValid();
  192. }
  193.  
  194. void $$CNTRITEM_CLASS$$::Dump(CDumpContext& dc) const
  195. {
  196.     $$CNTRITEM_BASE_CLASS$$::Dump(dc);
  197. }
  198. #endif
  199.  
  200. /////////////////////////////////////////////////////////////////////////////
  201.